package cn.simon.service;


import cn.simon.mapper.UsersMapper;
import cn.simon.model.Users;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class UsersService {

    @Autowired
    private UsersMapper usersMapper;

    public List<Users> getAllUsers() {
        return usersMapper.getAllUsers();
    }


    public Users findByName(String username){
        QueryWrapper<Users> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username",username);
        Users users = usersMapper.selectOne(queryWrapper);
        return users;
    }


    public Users findById(Integer id){
        Wrapper<Users> queryWrapper = new QueryWrapper<Users>().eq("users_id",id);
        return usersMapper.selectOne(queryWrapper);
    }

    /**
     * 冻结用户
     */
    public Integer freezeUser(Integer id){
        return usersMapper.updateById(Users.builder().userId(id).userState(0).build());
    }

    /**
     * 激活用户
     */
    public  Integer unFreezeUser(Integer id){
        return usersMapper.updateById(Users.builder().userId(id).userState(1).build());
    }

    /**
     * 添加用户
     */

    public int addUsers(Users users){
        return usersMapper.addUsers(users);
    }

}

